<?php
/**
 * ooPHP - object oriented PHP framework
 * @author Kamil Mikolajczyk ( rego (at) gazeta (dot) pl )
 * @version 1.0
 *
 */
 
 
class Input
{

	var $type;
	var $name;
	var $attribs = "";

	function Input($type, $name, $attribs = "")
	{
		$this -> type = $type;
		$this -> name = $name;
		$this -> attribs = $attribs;
	}
	
	function render($indents = 0)
	{
		Printer::writeln('<input type="'.$this -> type.'" name="'.$this -> name.'" '.($this -> attribs != "" ? $this -> attribs.' ' : '').'/>', $indents);
	}
}
 
 
/**
 * 
 * @author Kamil Mikolajczyk ( rego (at) gazeta (dot) pl )
 * @version 1.0
 *
 */
 class Form
 {
 	var $method = "";
 	var $action = "";
 	var $elements = Array();
 	var $submit = "";
 	var $attribs = "";
	var $id = null;
	var $class = null;
 	
 	function Form($action = "", $method = "", $id = null, $class = null)
 	{
 		if($action != "")
 			$this -> setAction($action);
 		if($method != "")
 			$this -> setMethod($method);
		if($class)
			$this -> class = $class;
		if($id)
			$this -> id = $id;
 	}
 	
 	function createLoggingForm($userName, $passName, $userLabel, $passLabel, $submitLabel, $action, $message = "")
 	{
 		$this -> setMethod('POST');
 		$this -> setAction($action);
 		$this -> addText('text', $userName, "", $userLabel, "");
 		$this -> addText('password', $passName, "", $passLabel, "");
 		$this -> elements[] = '<p class="loggerMessage">'.$message.'</p>';
 		$this -> addSubmit($submitLabel); 
 	}
 	
 	function addText($type, $name, $value = "", $label = "", $events = "")
 	{
 		$element = '';
 		if($label != "")
 		{
 			$element .= '<label for="'.$name.'">'.$label.'</label>';
 		}
 		$element .= '<input type="'.$type.'" ';
 		$element .= 'name="'.$name.'" ';
 		$element .= ($value != "" ? 'value="'.$value.'" ' : '');
 		$element .= $events.'/>';
 		
 		$this -> elements[] = $element;
 	}
	
 	function addElement($e)
 	{ 		
 		$this -> elements[] = $e;
 	}	
 	
 	function addSubmit($value)
 	{
 		$this -> submit = '<input type="submit" value="'.$value.'"/>';
 	}
 	
 	function addInput($type, $name, $attribs = "")
 	{
 		$this -> elements[] = new Input($type, $name, $attribs);
 	}
 	 	
 	function setAction($a)
 	{
 		$this -> action = $a;
 	}
 	
 	function setMethod($m)
 	{
 		$this -> method  = $m;
 	}
 	
 	function getMethod()
 	{
 		return $this -> method;
 	}
 	
 	function setAttributes($a)
 	{
 		$this -> attribs  = $a;
 	}
 	
 	function getAttributes()
 	{
 		return $this -> attribs;
 	}
 	
 	function render($indents = 0)
 	{
 		Printer::writeln('<form '.($this -> method != "" ? 'method="'.$this -> method.'" ' : '').($this -> class != "" ? 'class="'.$this -> class.'" ' : '').($this -> id != "" ? 'id="'.$this -> id.'" ' : '').($this -> action != 'action=""' ? 'action="'.$this -> action.'" ' : '').'/>', $indents);
 		foreach($this -> elements as $e)
 		{
 			$e -> render($indents + 1);
 		}
 		Printer::writeln($this -> submit, $indents + 1);
 		Printer::writeln('</form>', $indents);
 	}
 }
 
 ?>